package com.gree.portal.service.impl;

import com.gree.commom.utils.CookieUtil;
import com.gree.portal.service.CookinService;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Service
public class CookinServiceImpl implements CookinService {

    /**
     * 设置cookie
     * @param request
     * @param response
     * @param ticket
     * @return
     */
    @Override
    public boolean setCookie(HttpServletRequest request, HttpServletResponse response, String ticket) {
        try {
            CookieUtil.setCookie(request,response,"userTicket",ticket);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 获取cooke信息
     * @param request
     * @return
     */
    @Override
    public String getCookie(HttpServletRequest request) {
        return CookieUtil.getCookieValue(request,"userTicket");
    }

    /**
     * 删除cooke信息
     * @param request
     * @param response
     * @return
     */
    @Override
    public boolean deleteCookie(HttpServletRequest request, HttpServletResponse response) {
        try {
            CookieUtil.deleteCookie(request,response,"userTicket");
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
}
